﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DDD.Core;
using FloatComparer = DDDTest.Helper.FloatComparer;

namespace DDDTest.Core {
    [TestClass]
    public class TestVertexArray {
        [TestMethod]
        public void Test_New1 () {
            var varry = new VertexArray<byte> (4, 3);

            Assert.AreEqual (4, varry.VertexCount);
            Assert.AreEqual (3, varry.ComponentCount);
            Assert.AreEqual (ComponentType.Byte, varry.ComponentType);
        }

        /// <summary>
        /// GetSetの基本テスト
        /// </summary>
        [TestMethod]
        public void Test_GetSet_1 () {
            var varry = new VertexArray<byte> (4, 3);
            var src = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
            var expected = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
            var buf = new byte[12];

            varry.Set (0, 4, src);
            varry.Get (0, 4, buf);

            CollectionAssert.AreEqual (expected, buf);
        }

        /// <summary>
        /// 開始位置をずらしてGetSetするテスト
        /// </summary>
        [TestMethod]
        public void Test_GetSet_2 () {
            var varry = new VertexArray<byte> (4, 3);
            var src = new byte[] { 1, 2, 3, 4, 5, 6 };
            var expected = new byte[] { 1, 2, 3, 4, 5, 6 };
            var buf = new byte[6];

            varry.Set (2, 2, src);
            varry.Get (2, 2, buf);

            CollectionAssert.AreEqual (expected, buf);
        }



        [TestMethod]
        public void Test_Enumerator () {
            var varry = new VertexArray<byte> (4, 3);
            var src = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };

            varry.Set (0, 4, src);

            var sum = 0;
            foreach (var v in varry) {
                sum += v;
            }

            Assert.AreEqual (78, sum);
        }

        /// <summary>
        /// Byte型のテスト
        /// </summary>
        [TestMethod]
        public void Test_Byte1 () {
            var varry = new VertexArray<byte> (4, 3);
            var src = new byte[] { 1, 2, 3, 4, 5, 6 };
            var expected = new byte[] { 1, 2, 3, 4, 5, 6 };
            var buf = new byte[6];

            varry.Set (0, 2, src);
            varry.Get (0, 2, buf);

            CollectionAssert.AreEqual (expected, buf);
        }



        /// <summary>
        /// Short型のテスト
        /// </summary>
        [TestMethod]
        public void Test_Short1 () {
            var varry = new VertexArray<short> (4, 3);
            var src = new short[] { 1, 2, 3, 4, 5, 6 };
            var expected = new short[] { 1, 2, 3, 4, 5, 6 };
            var buf = new short[6];

            varry.Set (0, 2, src);
            varry.Get (0, 2, buf);

            CollectionAssert.AreEqual (expected, buf);
        }



        /// <summary>
        /// UShort型のテスト
        /// </summary>
        [TestMethod]
        public void Test_UShort1 () {
            var varry = new VertexArray<ushort> (4, 3);
            var src = new ushort[] { 1, 2, 3, 4, 5, 6 };
            var expected = new ushort[] { 1, 2, 3, 4, 5, 6 };
            var buf = new ushort[6];

            varry.Set (0, 2, src);
            varry.Get (0, 2, buf);

            CollectionAssert.AreEqual (expected, buf);
        }



        /// <summary>
        /// Int型のテスト
        /// </summary>
        [TestMethod]
        public void Test_Int1 () {
            var varry = new VertexArray<int> (4, 3);
            var src = new int[] { 1, 2, 3, 4, 5, 6 };
            var expected = new int[] { 1, 2, 3, 4, 5, 6 };
            var buf = new int[6];

            varry.Set (0, 2, src);
            varry.Get (0, 2, buf);

            CollectionAssert.AreEqual (expected, buf);
        }



        /// <summary>
        /// UInt型のテスト
        /// </summary>
        [TestMethod]
        public void Test_Uint1 () {
            var varry = new VertexArray<uint> (4, 3);
            var src = new uint[] { 1, 2, 3, 4, 5, 6 };
            var expected = new uint[] { 1, 2, 3, 4, 5, 6 };
            var buf = new uint[6];

            varry.Set (0, 2, src);
            varry.Get (0, 2, buf);

            CollectionAssert.AreEqual (expected, buf);
        }


    }
}
